<script setup>
//图标导入
import {
    Management,
    Promotion,
    UserFilled,
    User,
    Crop,
    EditPen,
    SwitchButton,
    CaretBottom,
    Avatar,
    Edit,
    Checked,
    List
} from '@element-plus/icons-vue'
import privilegeIcon from '@/assets/privilege.png'
import privilegeManageIcon from '@/assets/privilegeManage.png'//权限管理
import privilegeApplyIcon from '@/assets/privilegeApply.png'//权限申请
import privilegeVerifyIcon from '@/assets/privilegeVerify.png'//权限审批

import coldStorageIcon from '@/assets/coldStorage.png'//冷库图标
import coldStorageConstructionIcon from '@/assets/coldStorageConstruction.png'//建造、维修
import coldStorageUseIcon from '@/assets/coldStorageUse.png'//使用
import coldStorageInIcon from '@/assets/coldStorageIn.png'//入库
import coldStorageOutIcon from '@/assets/coldStorageOut.png'//出库
import coldStorageSensorIcon from '@/assets/coldStorageSensor.png'//传感器

import userIcon from '@/assets/user.png'//我的
import userChangeAvatarIcon from '@/assets/userChangeAvatar.png'//修改头像
import userChangePasswordIcon from '@/assets/userChangePassword.png'//修改密码

import messageIcon from '@/assets/message.png'//消息
import avatar from '@/assets/default.png';
// import newAvatar from '@/assets/123.png'

import useUserInfoStore from '@/stores/userInfo.js';
const userInfoStore = useUserInfoStore();


// //获取角色称呼
// const userRole = ref();//角色称呼
// const getUserRole = () => {
//     userInfoStore.info.role;
// }

import { useRouter } from 'vue-router';
import { ElMessage, ElMessageBox } from 'element-plus';
import { useTokenStore } from '@/stores/token';
import { ref } from 'vue';
const tokenStore = useTokenStore();
const router = useRouter();
//条目被点击后调用的函数
const handleCommand = (command) => {
    //判断指令
    if (command === 'logout') {
        //退出登录
        ElMessageBox.confirm(
            '确认要退出?',
            '提示',
            {
                confirmButtonText: '确认',
                cancelButtonText: '取消',
                type: 'warning',
            }
        )
            .then(async () => {
                // console.log('退出id:' + row.id)
                //退出

                //清空pinia中存储的token及个人信息
                tokenStore.removeToken();
                userInfoStore.removeInfo();
                //跳转到登录页面
                router.push('/login');
                ElMessage({
                    type: 'success',
                    message: '退出登录成功',
                })
            })
            .catch(() => {
                ElMessage({
                    type: 'info',
                    message: '取消退出登录',
                })
            })

    } else {
        //路由
        router.push('/user/' + command);
    }
}










import useSystemParameter from '@/stores/useSystemParameter'
const systemParameter = useSystemParameter();



</script>

<template>
    <!-- element-plus中的容器 -->
    <el-container class="layout-container">
        <!-- 左侧菜单 -->
        <el-aside width="200px">
            <div class="el-aside__logo"></div>
            <!-- element-plus的菜单标签 -->
            <el-menu active-text-color="#ffd04b" background-color="#014398" text-color="#fff" router>
                <el-sub-menu index="1">
                    <template #title>
                        <el-icon class="custom-itom">
                            <img :src="privilegeIcon" class="el-icon-img">
                        </el-icon>
                        <span>权限</span>
                    </template>
                    <el-menu-item index="/privileges/manage">
                        <el-icon class="custom-itom">
                            <img :src="privilegeManageIcon" class="el-icon-img">
                        </el-icon>
                        <span>权限管理</span>
                    </el-menu-item>
                    <el-menu-item index="/privileges/apply">
                        <el-icon class="custom-itom">
                            <img :src="privilegeApplyIcon" class="el-icon-img">
                        </el-icon>
                        <span>权限申请</span>
                    </el-menu-item>
                    <el-menu-item index="/privileges/verify">
                        <el-icon class="custom-itom">
                            <img :src="privilegeVerifyIcon" class="el-icon-img">
                        </el-icon>
                        <span>权限审批</span>
                    </el-menu-item>
                </el-sub-menu>
                <el-sub-menu index="2">
                    <template #title>
                        <el-icon class="custom-itom">
                            <img :src="coldStorageIcon" class="el-icon-img">
                        </el-icon>
                        <span>冷库</span>
                    </template>
                    <el-menu-item index="/coldstorage/construct">
                        <el-icon class="custom-itom">
                            <img :src="coldStorageConstructionIcon" class="el-icon-img">
                        </el-icon>
                        <!-- 包含新建、前往维修、维修验收、拆除 -->
                        <span>冷库施工</span>
                    </el-menu-item>
                    <el-menu-item index="/coldstorage/sensor">
                        <el-icon class="custom-itom">
                            <img :src="coldStorageSensorIcon" class="el-icon-img">
                        </el-icon>
                        <!-- 注册、发送测试数据、修改、注销 -->
                        <span>传感器管理</span>
                    </el-menu-item>
                    <el-menu-item index="/coldstorage/use">
                        <el-icon class="custom-itom">
                            <img :src="coldStorageUseIcon" class="el-icon-img">
                        </el-icon>
                        <!-- 开机，入库，出库，关机，更改阈值，日志 -->
                        <span>冷库使用</span>
                    </el-menu-item>
                </el-sub-menu>



                <!-- <el-menu-item index="/article/category">
                    <el-icon>
                        <Management />
                    </el-icon>
                    <span>文章分类</span>
                </el-menu-item> -->
                <!-- <el-menu-item index="/article/manage">
                    <el-icon>
                        <Promotion />
                    </el-icon>
                    <span>文章管理</span>
                </el-menu-item> -->



                <!-- 子菜单标签 -->
                <el-sub-menu>
                    <template #title>
                        <el-icon class="custom-itom">
                            <img :src="userIcon" class="el-icon-img">
                        </el-icon>
                        <span>个人中心</span>
                    </template>
                    <el-menu-item index="/user/info">
                        <el-icon>
                            <Edit />
                        </el-icon>
                        <span>基本资料</span>
                    </el-menu-item>
                    <el-menu-item index="/user/avatar">
                        <el-icon class="custom-itom">
                            <img :src="userChangeAvatarIcon" class="el-icon-img">
                        </el-icon>
                        <span>更换头像</span>
                    </el-menu-item>
                    <el-menu-item index="/user/resetPassword">
                        <el-icon class="custom-itom">
                            <img :src="userChangePasswordIcon" class="el-icon-img">
                        </el-icon>
                        <span>修改密码</span>
                    </el-menu-item>
                </el-sub-menu>

                <el-menu-item index="/user/message">
                    <el-icon class="custom-itom">
                        <img :src="messageIcon" class="el-icon-img">
                    </el-icon>
                    <span>消息</span>
                    <el-badge v-if="userInfoStore.unreadMessageNum > 0" :value="userInfoStore.unreadMessageNum"
                        class="item">
                        <!-- 一个空目标给badge踩 -->
                        <div></div>
                    </el-badge>
                </el-menu-item>

            </el-menu>
        </el-aside>
        <!-- 右侧主区域 -->
        <el-container>
            <!-- 头部区域 -->
            <el-header >
                <div>
                    <el-tag size="large">{{ userInfoStore.role.roleName ? userInfoStore.role.roleName : '' }}</el-tag>
                    {{ " " }}
                    <strong>
                        {{
                                userInfoStore.info.nickname ? '[' + userInfoStore.info.nickname + ']' + userInfoStore.info.username :
                                    userInfoStore.info.username
                            }}
                    </strong>

                </div>
                    <!-- 下拉菜单 -->
                    <!-- comand:条目被点击后触发，在时间函数上可以声明一个函数，接受条目对应的指令 -->
                    <el-dropdown placement="bottom-end" @command="handleCommand">
                        <span class="el-dropdown__box">
                            <!-- <img :src="userInfoStore.info.userPic?userInfoStore.info.userPic:avatar" alt="Local Image"> -->

                            <el-avatar :src="userInfoStore.info.userPic ? userInfoStore.info.userPic : avatar" />
                            <el-icon>
                                <CaretBottom />
                            </el-icon>
                        </span>
                        <template #dropdown>
                            <el-dropdown-menu>
                                <el-dropdown-item command="info" :icon="User">基本资料</el-dropdown-item>
                                <el-dropdown-item command="avatar" :icon="Crop">更换头像</el-dropdown-item>
                                <el-dropdown-item command="resetPassword" :icon="EditPen">重置密码</el-dropdown-item>
                                <el-dropdown-item command="logout" :icon="SwitchButton">退出登录</el-dropdown-item>
                            </el-dropdown-menu>
                        </template>
                    </el-dropdown>
            </el-header>
            <!-- 中间区域 -->
            <el-main>
                <!-- <div style="width: 1290px; height: 570px;border: 1px solid red;">
                    内容展示区
                </div> -->
                <router-view></router-view>
            </el-main>
            <!-- 底部区域 -->
            <el-footer>From GDUPT By AlongWu;Email 2956079649@qq.com</el-footer>
        </el-container>
    </el-container>
</template>

<style lang="scss" scoped>
.layout-container {
    height: 100vh;

    .el-aside {
        background-color: #014398;

        &__logo {
            height: 120px;
            background: url('@/assets/logo_blue2.png') no-repeat center / 120px auto;
            margin-top: 20px;
            /* 调整这个值来移动 logo */
        }

        .el-menu {
            border-right: none;
        }
    }

    .el-header {
        background-color: #fff;
        display: flex;
        align-items: center;
        justify-content: space-between;

        .el-dropdown__box {
            display: flex;
            align-items: center;

            .el-icon {
                color: #999;
                margin-left: 10px;
            }

            &:active,
            &:focus {
                outline: none;
            }
        }
    }

    .el-footer {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        color: #666;
    }
}





/* Element Plus 图标的额外样式 */
.el-icon>svg {
    /* 如果 Element Plus 图标需要额外的样式调整 */
}



/* 为 el-badge 添加左边距 */
.item {
    margin-left: 1em;
    /* 1em 大约相当于当前字体大小的空间，可以根据需要调整 */
}
</style>
